<%@page import="com.spreedairy.portal.service.RecommendationLocalServiceUtil"%>
<%@page import="com.spreedairy.common.ShoppingPreferences"%>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineObjects />

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://liferay.com/tld/portlet" prefix="liferay-portlet" %>
<%@ taglib uri="http://liferay.com/tld/security" prefix="liferay-security" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ taglib uri="http://liferay.com/tld/util" prefix="liferay-util" %>

<%@ page import="com.liferay.portal.kernel.util.ListUtil" %>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%@ page import="com.liferay.portal.kernel.bean.BeanParamUtil" %>
<%@ page import="com.liferay.portlet.shopping.model.ShoppingCategory" %>
<%@ page import="com.liferay.portlet.shopping.model.ShoppingCategoryConstants" %>
<%@ page import="com.liferay.portlet.shopping.CategoryNameException" %>
<%@ page import="com.liferay.portlet.shopping.model.ShoppingCategory" %>
<%@ page import="com.liferay.portlet.shopping.service.ShoppingCategoryLocalServiceUtil" %>
<%@ page import="com.liferay.portlet.shopping.service.ShoppingCartLocalServiceUtil" %>
<%@ page import="com.liferay.portal.kernel.dao.search.SearchContainer" %>
<%@ page import="com.liferay.portal.kernel.dao.search.SearchEntry" %>
<%@ page import="com.liferay.portal.kernel.dao.search.ResultRow" %>
<%@ page import="com.liferay.portal.kernel.util.Validator" %>
<%@ page import="com.liferay.portlet.shopping.model.ShoppingItem" %>
<%@ page import="com.liferay.portlet.shopping.service.ShoppingItemLocalServiceUtil" %>
<%@ page import="com.liferay.portlet.shopping.NoSuchCategoryException" %>

<%@ page import="com.liferay.portal.kernel.util.Constants" %>
<%@ page import="com.liferay.portal.kernel.portlet.LiferayWindowState" %>

<%@ page import="com.liferay.portlet.PortletURLUtil" %>
<%@ page import="com.liferay.portal.theme.ThemeDisplay" %>

<%@ page import="com.liferay.portal.kernel.util.StringBundler" %>
<%@ page import="com.liferay.portal.kernel.util.StringComparator" %>
<%@ page import="com.liferay.portal.kernel.util.StringPool" %>
<%@ page import="com.liferay.portal.kernel.util.StringUtil" %>
<%@ page import="com.liferay.portal.kernel.util.UnicodeFormatter" %>
<%@ page import="com.liferay.portal.kernel.util.UnicodeProperties" %>
<%@ page import="com.liferay.portal.kernel.language.LanguageUtil" %>
<%@ page import="com.liferay.portal.kernel.language.LanguageWrapper" %>
<%@ page import="com.liferay.portal.kernel.language.UnicodeLanguageUtil" %>
<%@ page import="com.liferay.portal.kernel.util.PrefsParamUtil" %>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>

<%@ page import="javax.portlet.WindowState" %>
<%@ page import="javax.portlet.PortletMode" %>
<%@ page import="javax.portlet.PortletURL" %>
<%@ page import="javax.portlet.RenderRequest" %>
<%@ page import="javax.portlet.RenderResponse" %>
<%@ page import="javax.portlet.ResourceRequest" %>
<%@ page import="javax.portlet.ResourceResponse" %>

<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Arrays" %>
<%@ page import="java.util.List" %>


<%@ page import="com.liferay.portal.kernel.util.ArrayUtil" %>
<%@ page import="javax.portlet.ActionRequest" %>
<%@ page import="javax.portlet.PortletPreferences" %>
<%@ page import="com.liferay.portal.kernel.util.GetterUtil" %>
<%@ page import="com.liferay.portal.kernel.util.LocalizationUtil" %>



<%@ page import="com.liferay.portlet.shopping.service.ShoppingItemPriceLocalServiceUtil" %>
<%@ page import="com.liferay.portal.kernel.util.GetterUtil" %>
<%@ page import="com.liferay.portlet.shopping.service.ShoppingItemFieldLocalServiceUtil" %>
<%@ page import="com.liferay.portlet.shopping.model.ShoppingCategoryConstants" %>

<%@ page import="com.liferay.portal.kernel.dao.search.SearchContainer" %>
<%@ page import="com.liferay.portal.kernel.util.StringBundler" %>
<%@ page import="com.liferay.portal.kernel.util.UnicodeFormatter" %>
<%@ page import="com.liferay.portlet.shopping.model.ShoppingCategory" %>

<%@ page import="com.liferay.portal.kernel.util.FastDateFormatFactoryUtil" %>
<%@ page import="java.text.Format" %>
<%@ page import="java.util.Locale" %>
<%@ page import="java.util.TimeZone" %>
<%@ page import="com.liferay.portlet.PortalPreferences" %>
<%@ page import="com.liferay.portlet.PortletPreferencesFactoryUtil" %>
<%@ page import="java.text.NumberFormat" %>
<%@ page import="java.util.Currency" %>

<%@ page import="com.liferay.portlet.shopping.model.ShoppingItem" %>
<%@ page import="com.liferay.portlet.shopping.model.ShoppingItemPrice" %>
<%@ page import="com.liferay.portlet.shopping.model.ShoppingItemPrice" %>
<%@ page import="com.liferay.portlet.shopping.model.ShoppingItemPriceConstants" %>
<%@ page import="com.liferay.portlet.shopping.model.ShoppingItemField" %>
<%@ page import="com.liferay.portlet.shopping.DuplicateItemSKUException" %>
<%@ page import="com.liferay.portlet.shopping.ItemNameException" %>
<%@ page import="com.liferay.portlet.shopping.ItemSKUException" %>
<%@ page import="com.liferay.portlet.shopping.model.ShoppingItemPriceConstants" %>
<%@ page import="com.liferay.portlet.shopping.model.ShoppingItemField" %>
<%@ page import="com.liferay.portlet.shopping.DuplicateItemSKUException" %>
<%@ page import="com.liferay.portlet.shopping.ItemNameException" %>
<%@ page import="com.liferay.portlet.shopping.ItemSKUException" %>


<%@ page import="com.liferay.portal.kernel.util.OrderByComparator" %>
<%@page import="java.util.Enumeration"%>
<%@page import="com.liferay.portal.kernel.util.PropertiesUtil"%>
<%@page import="java.util.Properties"%>
<%@page import="com.liferay.portal.kernel.util.OrderedProperties"%>
<%@page import="com.liferay.portlet.shopping.model.ShoppingCartItem"%>
<%@page import="com.liferay.portlet.shopping.model.ShoppingCart"%>
<%@page import="com.liferay.portlet.shopping.model.ShoppingCoupon"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.Iterator"%>
<%@page import="com.liferay.portlet.shopping.CartMinQuantityException"%>
<%@page import="java.util.Set"%>
<%@page import="com.liferay.portal.kernel.servlet.SessionErrors"%>
<%@page import="com.liferay.portlet.shopping.CouponActiveException"%>
<%@page import="com.liferay.portlet.shopping.CouponEndDateException"%>
<%@page import="com.liferay.portlet.shopping.CouponStartDateException"%>
<%@page import="com.liferay.portlet.shopping.NoSuchCouponException"%>
<%@page import="javax.portlet.PortletSession"%>
<%@page import="com.liferay.portlet.shopping.model.ShoppingOrder"%>
<%@page import="com.liferay.portal.kernel.util.CalendarUtil"%>


<%@page import="java.util.Calendar"%>
<%@page import="com.liferay.portal.kernel.util.CalendarFactoryUtil"%>
<%@page import="com.liferay.portlet.shopping.CouponCodeException"%>
<%@page import="com.liferay.portlet.shopping.CouponDateException"%>
<%@page import="com.liferay.portlet.shopping.CouponDescriptionException"%>
<%@page import="com.liferay.portlet.shopping.CouponDiscountException"%>
<%@page import="com.liferay.portlet.shopping.CouponMinimumOrderException"%>
<%@page import="com.liferay.portlet.shopping.CouponNameException"%>
<%@page import="com.liferay.portlet.shopping.DuplicateCouponCodeException"%>
<%@page import="com.liferay.portal.kernel.util.HtmlUtil"%>
<%@page import="com.liferay.portlet.shopping.model.ShoppingCouponConstants"%>
<%@page import="com.liferay.portlet.shopping.CouponLimitCategoriesException"%>
<%@page import="com.liferay.portlet.shopping.CouponLimitSKUsException"%>

<%@page import="com.liferay.portlet.PortletURLFactoryUtil"%>
<%@page import="com.spreedairy.portal.model.CustomField" %>
<%@page import="com.liferay.portal.kernel.cache.Lifecycle"%>
<%@page import="javax.portlet.PortletRequest"%>
<%@page import="com.liferay.portal.model.Region"%>
<%@page import="com.liferay.portal.model.Country"%>
<%@page import="com.liferay.portal.service.RegionServiceUtil"%>
<%@page import="com.liferay.portal.service.CountryServiceUtil"%>
<%@page import="com.liferay.portlet.shopping.service.ShoppingItemServiceUtil"%>
<%@page import="com.liferay.portal.kernel.dao.orm.OrderFactoryUtil"%>
<%@page import="com.liferay.portal.kernel.dao.orm.DynamicQuery"%>
<%@page import="com.liferay.portal.kernel.dao.orm.DynamicQueryFactoryUtil"%>
<%@page import="com.liferay.portal.kernel.util.PortalClassLoaderUtil"%>
<%@page import="com.liferay.portlet.shopping.model.ShoppingOrderItem"%>
<%@page import="com.liferay.portlet.shopping.service.ShoppingOrderItemLocalServiceUtil"%>
<%@page import="com.liferay.portlet.shopping.service.persistence.ShoppingItemUtil"%>
<%@page import="com.liferay.portal.kernel.dao.orm.PropertyFactoryUtil"%>
<%@page import="com.liferay.portal.service.persistence.LayoutUtil"%>
<%@page import="java.text.DecimalFormatSymbols" %>
<%@page import="java.text.DecimalFormat" %>
<%@ page import="com.liferay.portlet.shopping.model.ShoppingOrderConstants"%>

<%@page import="com.spreedairy.portal.service.CustomFieldLocalServiceUtil"%>
<%@page import="com.spreedairy.portal.model.CustomField"%>
<%@page import="com.liferay.portlet.shopping.model.ShoppingCategoryConstants"%>
<%@page import="com.liferay.portal.kernel.bean.BeanParamUtil"%>
<%@page import="com.liferay.portlet.shopping.service.ShoppingCategoryLocalServiceUtil"%>
<%@page import="com.liferay.portlet.shopping.model.ShoppingCategory"%>
<%@page import="com.liferay.portal.kernel.exception.PortalException"%>
<%@page import="com.liferay.portal.kernel.exception.SystemException"%>

<liferay-theme:defineObjects />

<%
	PortalPreferences portalPrefs = PortletPreferencesFactoryUtil.getPortalPreferences(request);
	
	 ShoppingPreferences shoppingPrefs = ShoppingPreferences.getInstance(company.getCompanyId(), scopeGroupId);
	
	Currency currency = Currency.getInstance(shoppingPrefs.getCurrencyId());
	
	NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(locale);
	
	DecimalFormatSymbols dfs = new DecimalFormatSymbols();
	dfs.setCurrency(currency);
	if (currency.getSymbol().equalsIgnoreCase("INR")) {
	    String rupeeSymbol = "Rs.";
	    
	    dfs.setCurrencySymbol(rupeeSymbol);
	}
	((DecimalFormat)currencyFormat).setDecimalFormatSymbols(dfs);
	currencyFormat.setCurrency(currency);
	currencyFormat.setCurrency(currency); 
	
	Format dateFormatDateTime = FastDateFormatFactoryUtil.getDateTime(locale, timeZone);
	
	NumberFormat doubleFormat = NumberFormat.getNumberInstance(locale);
	
	doubleFormat.setMaximumFractionDigits(2);
	doubleFormat.setMinimumFractionDigits(2);
	
	NumberFormat percentFormat = NumberFormat.getPercentInstance(locale);
	
	NumberFormat taxFormat = NumberFormat.getPercentInstance(locale);
	
	taxFormat.setMinimumFractionDigits(3);
	
	WindowState windowState = null;
	PortletMode portletMode = null;
	
	PortletURL currentURLObj = null;
	
	if (renderRequest != null) {
		windowState = renderRequest.getWindowState();
		portletMode = renderRequest.getPortletMode();
	
		currentURLObj = PortletURLUtil.getCurrent(renderRequest, renderResponse);
	}
	else if (resourceRequest != null) {
		windowState = resourceRequest.getWindowState();
		portletMode = resourceRequest.getPortletMode();
	
		currentURLObj = PortletURLUtil.getCurrent(resourceRequest, resourceResponse);
	}
	
	String currentURL = currentURLObj.toString();
	//String currentURL = PortalUtil.getCurrentURL(request);
	PortletPreferences preferences = null;
	
	if (renderRequest != null) {
		preferences = renderRequest.getPreferences();
	}
	
	String portletResource = ParamUtil.getString(request, "portletResource");
	
	if (Validator.isNotNull(portletResource)) {
		//preferences = PortletPreferencesFactoryUtil.getPortletSetup(request, portletResource);
	}
	
	String ctxPath = request.getContextPath();
	if (ctxPath != null && ctxPath.length()==1) {
		ctxPath = "";
	}
%>

<%
	//agent module
	String agentTabs = ParamUtil.getString(request, "agentTabs", "Purchase");
	PortletURL agentTabsURL = renderResponse.createRenderURL();
	agentTabsURL.setParameter("agentTabs", agentTabs);
%>
